clear
rng(23)

outer_counter = 1;
repeats = 5;
num_comps = 10;
num_moments = 5;
parpool('local',num_comps)

%%% BASELINE MODEL TAU COUNTERFACTUAL
%%% SYMMETRIC EXAMPLE PARAMETERS

%%% RUN AND SAVE SEPARATELY FOR EACH VALUE OF TAU
%kappa = 0.01;
%kappa = 0.5;
kappa = 1;
simulated_data_tau = [];
for tau = 1.05:0.01:3
disp(tau)
params = [0.1   0.0222    0.1398     tau     7   kappa];
iteration_data = zeros(1,num_moments);
counter=1;
while counter <= repeats
parfor computer_num = 1:num_comps
temp_data = steady_state_simulation_plots_counterfactuals_symmetric(params);
iteration_data = iteration_data+temp_data'; 
end
counter = counter+1
end
iteration_data = iteration_data./(repeats*num_comps);
simulated_data_tau = [simulated_data_tau; tau iteration_data];
outer_counter = outer_counter+1
end

%save('tau_counterfactuals_example_symmetric_params_kappa_001.mat','simulated_data_tau')
%save('tau_counterfactuals_example_symmetric_params_kappa_05.mat','simulated_data_tau')
save('tau_counterfactuals_example_symmetric_params_kappa_1.mat','simulated_data_tau')

%%% AFTER RUNNING THE ABOVE, LOAD SIMULATED DATA TO MAKE PLOTS

simulated_data_tau_kappa_001 = load('tau_counterfactuals_example_symmetric_params_kappa_001.mat');
simulated_data_tau_kappa_05 = load('tau_counterfactuals_example_symmetric_params_kappa_05.mat');
simulated_data_tau_kappa_1 = load('tau_counterfactuals_example_symmetric_params_kappa_1.mat');

%%% GROWTH 
hold on
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_001(:,2),10),'k','LineWidth',2.0)
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_05(:,2),10),'k','LineWidth',2.0)
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_1(:,2),10),'k','LineWidth',2.0)
axis([1 3 1.5 3.5])
yticks([1.5 2 2.5 3 3.5])
ytickformat('percentage')
ax = gca
ax.YAxis.FontWeight = 'bold';
ax.XAxis.FontWeight = 'bold';
ax.YAxis.FontSize = 16
ax.XAxis.FontSize = 16
set(gcf,'color','white')
hold off

%%% RELATIVE WAGE
hold on
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_001(:,3),10),'k')
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_05(:,3),10),'k')
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_1(:,3),10),'k')
xlabel('Trade Cost (\tau)')
title('Relative Wage US/OECD')
set(gcf,'color','white')
hold off

%%% TRADE SHARE
hold on
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_001(:,4),10),'k','LineWidth',2.0)
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_05(:,4),10),'k','LineWidth',2.0)
plot(simulated_data_tau(:,1),smooth(simulated_data_tau_kappa_1(:,4),10),'k','LineWidth',2.0)
set(gcf,'color','white')
ax = gca
ax.YAxis.FontWeight = 'bold';
ax.XAxis.FontWeight = 'bold';
ax.YAxis.FontSize = 16
ax.XAxis.FontSize = 16
hold off

%%% TRADE ELASTICITY
hold on
plot(simulated_data_tau(:,1),-smooth(simulated_data_tau_kappa_001(:,5),25),'k','LineWidth',2.0)
plot(simulated_data_tau(:,1),-smooth(simulated_data_tau_kappa_05(:,5),25),'k','LineWidth',2.0)
plot(simulated_data_tau(:,1),-smooth(simulated_data_tau_kappa_1(:,5),25),'k','LineWidth',2.0)
axis([1 3 0 7])
yticks([0 1 2 3 4 5 6 7])
set(gcf,'color','white')
ax = gca
ax.YAxis.FontWeight = 'bold';
ax.XAxis.FontWeight = 'bold';
ax.YAxis.FontSize = 16
ax.XAxis.FontSize = 16
hold off






